<?php

use Illuminate\Database\Seeder;
use App\Models\Role;
use Illuminate\Support\Facades\Log;

class RolesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Log::info('清空角色并重新创建');
        Role::truncate();
        $items = [
            [
                'code'=>'ADMIN',
                'name'=>'管理员',
                'remark'=>''
            ],
            [
                'code'=>'FACTORY',
                'name'=>'厂家',
                'remark'=>'代工厂角色'
            ],
            [
                'code'=>'AGENT',
                'name'=>'代理商',
                'remark'=>'代理商'
            ],
            [
                'code'=>'DISTRIBUTOR',
                'name'=>'分销商',
                'remark'=>'分销商'
            ],
            [
                'code'=>'REPAIRER',
                'name'=>'维修方',
                'remark'=>'维修方'
            ],
            [
                'code'=>'STAFF',
                'name'=>'分润员工',
                'remark'=>'分润员工'
            ],
            [
                'code'=>'MERCHANT',
                'name'=>'终端伙伴',
                'remark'=>'终端伙伴'
            ]
        ];
        foreach ($items as $item){
            Role::updateOrCreate(['code'=>$item['code']],$item);
        } 
        Log::info('共创建'.count($items).'个角色');
    }
}
